import { defineStore } from 'pinia'
import { addOrEditDept, deleteDept, getDeptTree } from '@/service/index.js'
import responseMessage from '@/utils/response.js'

const useDeptStore = defineStore('dept', {
  state: () => ({
    deptTree: ''
  }),
  actions: {
    //获取部门树
    async getDeptTreeAction(searchParams) {
      const res = await getDeptTree(searchParams)
      this.deptTree = res.data
    },
    //删除部门
    async deleteDept(id) {
      const res = await deleteDept(id)
      responseMessage(res)
    },
    //编辑部门信息
    async addOrEditDept(addForm) {
      const res = await addOrEditDept(addForm)
      responseMessage(res)
    }
  }
})

export default useDeptStore
